package com.webservice.xmloper.activeinfo;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import com.thoughtworks.xstream.XStream;

public class ActiveStateXmlOper {

	public static String createQueryListXml(ActiveState activeState){
		
		XStream xs = new XStream();
		xs.processAnnotations(ActiveState.class);
		xs.setMode(XStream.NO_REFERENCES);
		return xs.toXML(activeState);
	}
	
	/**
	 * 解析活动状态xml文件
	 */
	public static ActiveState parseActiveStateXml(String xmlString){
		XStream xs = new XStream();
		xs.processAnnotations(ActiveState.class);
		InputStream myIn=new ByteArrayInputStream(xmlString.getBytes());
		return (ActiveState) xs.fromXML(myIn);
	}
	public static void main(String[] args) {
	
		String dataStr = "<activeState><idcId>苏ICP证070029号</idcId><houseAmount>1</houseAmount><houseState><houseId>19</houseId><spotState><spotId>a3fKnICGtV</spotId><spotType>eportal</spotType><spotIp>192.168.200.252</spotIp><cpu>29.0</cpu><memory><total>32947872</total><used>9637124</used><free>23310748</free><buffer>771452</buffer></memory><flow>0</flow>、<syn>0</syn><appState>0</appState><msg></msg></spotState></houseState><timeStamp>2013-03-06 17:16:21</timeStamp></activeState>";
		ActiveState curActiveState = parseActiveStateXml(dataStr);
/*		Memory memory11 = new Memory();
		memory11.setBuffer(new Long(1));
		memory11.setFree(new Long(1));
		memory11.setTotal(new Long(1));
		memory11.setUsed(new Long(1));
		
		Memory memory12 = new Memory();
		memory12.setBuffer(new Long(2));
		memory12.setFree(new Long(2));
		memory12.setTotal(new Long(2));
		memory12.setUsed(new Long(2));
		
		Memory memory21 = new Memory();
		memory21.setBuffer(new Long(1));
		memory21.setFree(new Long(1));
		memory21.setTotal(new Long(1));
		memory21.setUsed(new Long(1));
		
		Memory memory22 = new Memory();
		memory22.setBuffer(new Long(2));
		memory22.setFree(new Long(2));
		memory22.setTotal(new Long(2));
		memory22.setUsed(new Long(2));
		
		List<CpuObject> cpus11 = new ArrayList<CpuObject>();
		CpuObject cpu111 = new CpuObject();
		cpu111.setCpu(new Float(1.11));
		CpuObject cpu112 = new CpuObject();
		cpu112.setCpu(new Float(1.12));
		cpus11.add(cpu111);
		cpus11.add(cpu112);
		
		List<CpuObject> cpus12 = new ArrayList<CpuObject>();
		CpuObject cpu121 = new CpuObject();
		cpu121.setCpu(new Float(1.21));
		CpuObject cpu122 = new CpuObject();
		cpu122.setCpu(new Float(1.22));
		cpus12.add(cpu121);
		cpus12.add(cpu122);
		
		List<CpuObject> cpus21 = new ArrayList<CpuObject>();
		
		CpuObject cpu211 = new CpuObject();
		cpu211.setCpu(new Float(2.11));
		CpuObject cpu212 = new CpuObject();
		cpu212.setCpu(new Float(2.12));
		cpus21.add(cpu211);
		cpus21.add(cpu212);
		
		List<CpuObject> cpus22 = new ArrayList<CpuObject>();
		CpuObject cpu221 = new CpuObject();
		cpu221.setCpu(new Float(2.21));
		CpuObject cpu222 = new CpuObject();
		cpu222.setCpu(new Float(2.22));
		cpus22.add(cpu221);
		cpus22.add(cpu222);
		
		List<SpotState> spotStates1 = new ArrayList<SpotState>();
		SpotState spotState11 = new SpotState();
		spotState11.setSpotId("节点ID11");
		spotState11.setSpotType("节点类型11");
		spotState11.setSpotIp("节点IP11");
		spotState11.setCpus(cpus11);
		spotState11.setMemory(memory11);
		spotState11.setFlow(new Long(123));
		spotState11.setSyn(0);
		spotState11.setAppState(0);
		spotState11.setMsg("节点异常描述");
		
		SpotState spotState12 = new SpotState();
		spotState12.setSpotId("节点ID12");
		spotState12.setSpotType("节点类型12");
		spotState12.setSpotIp("节点IP12");
		spotState12.setCpus(cpus12);
		spotState12.setMemory(memory12);
		spotState12.setFlow(new Long(123));
		spotState12.setSyn(0);
		spotState12.setAppState(0);
		spotState12.setMsg("节点异常描述");
		
		
		spotStates1.add(spotState11);
		spotStates1.add(spotState12);
		
		List<SpotState> spotStates2 = new ArrayList<SpotState>();
		SpotState spotState21 = new SpotState();
		spotState21.setSpotId("节点ID21");
		spotState21.setSpotType("节点类型21");
		spotState21.setSpotIp("节点IP21");
		spotState21.setCpus(cpus21);
		spotState21.setMemory(memory21);
		spotState21.setFlow(new Long(123));
		spotState21.setSyn(0);
		spotState21.setAppState(0);
		spotState21.setMsg("节点异常描述");
		
		SpotState spotState22 = new SpotState();
		spotState22.setSpotId("节点ID22");
		spotState22.setSpotType("节点类型22");
		spotState22.setSpotIp("节点IP22");
		spotState22.setCpus(cpus22);
		spotState22.setMemory(memory22);
		spotState22.setFlow(new Long(123));
		spotState22.setSyn(0);
		spotState22.setAppState(0);
		spotState22.setMsg("节点异常描述");
		
		
		spotStates2.add(spotState21);
		spotStates2.add(spotState22);
		
		
		List<HouseState> houseStates = new ArrayList<HouseState>();
		HouseState houseSate1 = new HouseState();
		houseSate1.setHouseId("123456");
		houseSate1.setSpotStates(spotStates1);
		houseStates.add(houseSate1);
		
		HouseState houseSate2 = new HouseState();
		houseSate2.setHouseId("789012");
		houseSate2.setSpotStates(spotStates2);
		houseStates.add(houseSate2);
		
		ActiveState activeState = new ActiveState();
		activeState.setIdcId("idcId");
		activeState.setHouseAmount(3);
		activeState.setHouseStates(houseStates);
		activeState.setTimeStamp("2012-09-09 09:09:09");
		System.out.println(createQueryListXml(activeState));*/
	}
}
